﻿using System;
using System.Activities;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
using System.Text;
using System.Web;
using Zeus.Comunicaciones.Componentes;
using Zeus.Comunicaciones.Entidades;

namespace Zeus.Comunicaciones.Servicios.Rest
{
    [ServiceContract]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
    public class GenericService
    {
        [WebInvoke(Method = "POST", UriTemplate = "InvocarAccionObject", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
        public ServiceResponseObject InvocarAccionObject(Peticion peticion)
        {
            Procesos proceso = new Procesos { ValidarToken = true };

            ServiceResponseObject response = proceso.InvocarAccion<ServiceResponseObject>(peticion);
            
            return response;
        }

        [WebInvoke(Method = "POST", UriTemplate = "InvocarAccionSingle", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
        public ServiceResponseSingleEntity InvocarAccionSingle(Peticion peticion)
        {
            Procesos proceso = new Procesos { ValidarToken = true };

            ServiceResponseSingleEntity response = proceso.InvocarAccion<ServiceResponseSingleEntity>(peticion);

            return response;
        }

        [WebInvoke(Method = "POST", UriTemplate = "InvocarAccionCollection", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
        public ServiceResponseCollection InvocarAccionCollection(Peticion peticion)
        {
            Procesos proceso = new Procesos { ValidarToken = true };

            ServiceResponseCollection response = proceso.InvocarAccion<ServiceResponseCollection>(peticion);

            return response;
        }

        [WebInvoke(Method = "POST", UriTemplate = "Login", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        public string Autenticar(string usuario, string contrasena)
        {
            Procesos proceso = new Procesos();
            ServiceResponseSingleEntity response = proceso.Autenticacion(usuario, contrasena);
            return response.Data.GetValue().ToString();
        }
    }
}